<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        class Stack{
            #items = [];

            push(data){
                this.#items.push(data);
            }

            peek(){
                return this.#items.at(-1);
            }

            pop(){
                return this.#items.pop();
            }

            isEmpty(){
                return this.#items.length==0
            }

            size(){
                return this.#items.length;
            }

            clear(){
                this.#items = [];
            }

            toString(){
                return this.#items.join('');
            }
        }

        function convert(decNumber,base){
            if(base>16){console.log('算不了16進制以上的，滾');return;}
            let stack = new Stack();
            let str = '';
            let baseString = '0123456789ABCDEF'
            while(decNumber>0){
                stack.push(decNumber%base);
                decNumber = Math.floor(decNumber/base);
            }
            while(!stack.isEmpty()){
                str+=baseString[stack.pop()];
            }
            return str;
        }

        console.log(convert(50,16));
    </script>
</body>
</html>